package ch.electronet.wjw.web.actions;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

import net.sf.json.JsonConfig;

import org.apache.struts2.interceptor.ServletResponseAware;

public abstract class JsonDataAction extends JsonBaseAction implements ServletResponseAware {

	private static final long serialVersionUID = 1L;
	private String status = "";

	@Override
	protected final Object doJson(JsonConfig config) {
		Map<String, Object> map = new LinkedHashMap<String, Object>();
		long start = new Date().getTime();
		map.put("data", getData(config));
		map.put("duration", new Date().getTime() - start);
		map.put("status", status);
		return map;
	}

	protected abstract Object getData(JsonConfig config);

	protected final void setStatus(String status) {
		this.status = status;
	}

}
